function toBinary(decimal) {
  const reminders = [];
  let reminder = decimal % 2;
  let quotient = Math.floor(decimal / 2);
  reminders.push(reminder);
  while (quotient) {
    reminder = quotient % 2;
    reminders.push(reminder);
    quotient = Math.floor(quotient / 2);
  }
  return reminders.reverse().join('');
}


let output = toBinary(5);
// output = toBinary(12);
// output = toBinary(50);
// output = toBinary(99);
console.log(output);